package com.bzs.batch.reconcile.batch.step;

import com.bzs.batch.reconcile.batch.itemreader.ItemReaderFile;
import com.bzs.batch.reconcile.batch.itemreader.SysTransactionReader;
import com.bzs.batch.reconcile.batch.itemwriter.ItemWriterFile;
import com.bzs.batch.reconcile.batch.itemwriter.SysToFileWriter;
import com.bzs.batch.reconcile.batch.listener.Listener;
import com.bzs.batch.reconcile.batch.myprocessor.MyProcessor;
import com.bzs.batch.reconcile.entity.HostFile;
import com.bzs.batch.reconcile.entity.SysTransactionflow;
import lombok.AllArgsConstructor;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Classname ConStep
 * @Author baozs
 * @Date 2021/12/20 23:47
 * @Version 1.0
 * @Description
 **/
@Configuration
@AllArgsConstructor
public class ConStep {
    private final StepBuilderFactory stepBuilderFactory;
    private final ItemReaderFile itemReaderFile;
    private final ItemWriterFile itemWriterFile;

    private final SysTransactionReader sysTransactionReader;
    private final SysToFileWriter sysToFileWriter;

    private final MyProcessor myProcess;
    private final Listener listener;



    @Bean
    public Step getAConStep() {

        return stepBuilderFactory.get("getAConStep")
                .<HostFile, HostFile>chunk(100)
                //从文件读取核心流水
                .reader(itemReaderFile.getFileItemReader(""))
                .processor(myProcess.getMyProcessor(""))
                //将核心流水入库
                .writer(itemWriterFile)
                .listener(listener.getFileToDataListener(""))
                .build();
    }



    @Bean
    public Step getSysStep() throws Exception {
        return stepBuilderFactory.get("getSysStep")
                .<SysTransactionflow, SysTransactionflow>chunk(100)
                .reader(sysTransactionReader.getSysTransactionReader())
                .listener(listener.getDataToFileListener(""))
                .writer(sysToFileWriter.getFileWrite("","",""))
                .build();
    }
}
